package org.fuxian.dao;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.fuxian.domain.MyHouse;

import java.util.List;

public interface MyHouseMapper {

    @Select("select * from myhouse where hflag = #{flag}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result( column = "sid", property = "sid"),
            @Result( column = "aid", property = "aid"),
            @Result(column = "sid", property = "sort", one = @One(select = "org.fuxian.dao.MySortMapper.findById", fetchType = FetchType.EAGER)),
            @Result(column = "aid", property = "area", one = @One(select = "org.fuxian.dao.MyAreaMapper.findById", fetchType = FetchType.EAGER))
    })
    List<MyHouse> findAll(@Param("flag") Integer flag);

    @Insert("insert into myhouse values(null, #{sid}, #{aid}, #{haddress}, #{hfh}, #{hhx}, #{hmj}, #{hcx}, #{hmoney}, #{hwf}, #{hdx}, #{hsf}, #{hmq}, #{dkd}, #{skd}, #{mkd}, #{hjp}, #{hremark}, #{himg}, #{hflag})")
    int add(MyHouse house);

    @Select("select * from myhouse where hid = #{hid}")
    MyHouse findById(Integer hid);

    @Update("<script>"
            + "update myhouse "
            + "<set> "
            + "<if test=\"sid!=0 and sid!=null\">"
            + "sid= #{sid},"
            + "</if>"
            + "<if test=\"aid!=0 and aid!=null\">"
            + "aid= #{aid},"
            + "</if>"
            + "<if test=\"haddress!=null\">"
            + "haddress=#{haddress},"
            + "</if>"
            + "<if test=\"hfh!=null\">"
            + "hfh=#{hfh},"
            + "</if>"
            + "<if test=\"hhx!=null\">"
            + "hhx=#{hhx},"
            + "</if>"
            + "<if test=\"hmj!=null\">"
            + "hmj=#{hmj},"
            + "</if>"
            + "<if test=\"hcx!=null\">"
            + "hcx=#{hcx},"
            + "</if>"
            + "<if test=\"hdx!=0\">"
            + "hdx= #{hdx},"
            + "</if>"
            + "<if test=\"hwf!=0\">"
            + "hwf= #{hwf},"
            + "</if>"
            + "<if test=\"hsf!=0\">"
            + "hsf= #{hsf},"
            + "</if>"
            + "<if test=\"hmq!=0\">"
            + "hmq= #{hmq},"
            + "</if>"
            + "<if test=\"dkd!=0\">"
            + "dkd= #{dkd},"
            + "</if>"
            + "<if test=\"skd!=0\">"
            + "skd= #{skd},"
            + "</if>"
            + "<if test=\"mkd!=0\">"
            + "mkd= #{mkd},"
            + "</if>"
            + "<if test=\"hmoney!=0\">"
            + "hmoney= #{hmoney},"
            + "</if>"
            + "<if test=\"hjp!=null\">"
            + "hjp= #{hjp},"
            + "</if>"
            + "<if test=\"himg!=null and himg!='' \">"
            + "himg= #{himg},"
            + "</if>"
            + "<if test=\"hremark!=null\">"
            + "hremark= #{hremark},"
            + "</if>"
            + "<if test=\"hflag!=null\">"
            + "hflag= #{hflag},"
            + "</if>"
            + "</set>"
            + " where hid=#{hid}</script>")
    int update(MyHouse house);
}
